package com.fattyCorps.game.obj.db;

import com.fattyCorps.common.packet.Item;
import com.fattyCorps.common.packet.Mail;
import com.fattyCorps.common.packet.hero.Hero;
import com.fattyCorps.common.packet.PacketMap;
import lombok.Data;

import java.util.List;

@Data
public class PlayerData implements Cloneable {
    private Integer createTime = 0;
    private Integer lv = 0;
    private Integer exp = 0;
    private Integer head;
    // 元宝
    private Integer money = 0;
    // 普通货币
    private Integer coin = 0;
    private Integer guanqia = 0;
    // 上次挂机开始时间
    private Integer lastHangTime = 0;
    // 上次免费抽卡开始时间
    private String lastFreeLotteryTime;
    private Integer globalMailId;
    private List<Integer> defLineupHeroIds;
    // 战力，玩家战力为上阵英雄战力之和
    private long combatVal;

    private PacketMap<Item> items = new PacketMap<>();
    private PacketMap<Hero> heroes = new PacketMap<>();
    private PacketMap<Mail> mails = new PacketMap<>();

    @Override
    public PlayerData clone() throws CloneNotSupportedException {
        PlayerData objClone = (PlayerData) super.clone();
        objClone.items = items.clone();
        objClone.heroes = heroes.clone();
        objClone.mails = mails.clone();
        return objClone;
    }

    public void setDefLineupHeroIds(List<Integer> v) {
        defLineupHeroIds = v;
        reCalcCombat();
    }

    public void reCalcCombat() {
        combatVal = 0;
        for (Integer heroId : defLineupHeroIds) {
            if (heroId <= 0) {
                continue;
            }

            Hero hero = heroes.get(heroId);
            if (hero == null) {
                continue;
            }

            combatVal += hero.getPropComp().getCombatVal();
        }
    }
}
